<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
    <hea>
        <script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
    </hea>
    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputLabel value="#{messages.Knowledge}"></h:outputLabel>
        </ui:define>
        <ui:define name="body">
            <h:outputScript library="javaScript" name="d3.v4.js" target="head"/>
            <h:outputScript library="javaScript" name="graphlib-dot.js" target="head"/>
            <h:outputScript library="javaScript" name="dagre-d3.js" target="head"/>
            <h:outputStylesheet library="css" name="dagre.css"/>
            <h:outputStylesheet library="css" name="a.css"/>
            <h:outputScript library="javaScript" name="remoteMathJax.js" target="head"/>
            <h:form styleClass="jsfcrud_list_form" prependId="false">
                <h:panelGrid columns="1">
                    <h:panelGrid columns="2">
                        <h:inputText value="#{knowledgeController.searchName}" immediate="true">
                            <f:ajax render="search"/>
                        </h:inputText>
                        <h:commandButton id="search" value="#{messages.Search} #{messages.Knowledge}" action="#{knowledgeController.search()}" immediate="true"
                                         disabled="#{null==knowledgeController.searchName}"/>
                    </h:panelGrid>
                    <h:panelGrid columns="2">
                        <h:outputLabel value="#{messages.Createdby} #{messages.Name1}"/>
                        <h:outputLabel value="#{knowledgeController.showedName(knowledgeController.selected)}" id="showedName"/>
                        <h:outputLabel value="#{messages.Name}"/>
                        <h:outputLabel value="#{knowledgeController.selected.name}" title="#{messages.Name}"/>
                        <h:outputLabel value="#{messages.Detail}"/>
                        <h:outputText escape="false"  value="#{knowledgeController.selected.details}" />
                        <h:outputLabel value="#{messages.Level}" dir="RTL"/>
                        <h:outputLabel value="#{knowledgeController.levelMap.get(knowledgeController.selected.levelnumber)}"/>
                        <h:outputLabel value="#{messages.KnowledgeType}" dir="RTL"/>
                        <h:outputLabel value="#{knowledgeController.knowledgeTypeMap.get(knowledgeController.selected.knowledgetype)}"/>                    
                    </h:panelGrid>

                    <ui:include src="../learningResource/resource4Knowledge.xhtml"/>

                    <c:forEach items="#{edgeamongknowledgeController.getPrecessorEdgeamongknowledge(knowledgeController.selected)}" var="edge">
                        <h:panelGroup>
                            <h:panelGrid columns="3">
                                <h:outputLabel value="#{messages.Predicate}#{messages.Name}"   dir="RTL"/>
                                <h:outputLabel value="#{edge.predicate.pname}"/>
                                <h:outputLabel value="#{messages.Knowledge}#{messages.Name}"   dir="RTL"/>
                                <h:outputLabel value="#{edge.predecessornode.name}"/>
                            </h:panelGrid>
                        </h:panelGroup>
                        <hr/>
                    </c:forEach>
                </h:panelGrid>
                <h:commandButton action="#{knowledgeController.submit4Reexamination()}" value="#{messages.Submit} #{messages.Reexamin}" immediate="true"/>
                <!--下面的命令按钮不加immediate="true"就会出错！！目前还没找到原因-->
                <h:panelGrid columns="5">
                    <h:commandButton value="#{messages.Create}" action="#{knowledgeController.prepareCreate()}" immediate="true"/>
                    <h:outputLabel value=" "/>
                    <h:commandButton value="#{messages.View} #{messages.All}" action="#{knowledgeController.prepareList()}" immediate="true"/>
                    <h:outputLabel value=" "/>
                    <h:commandButton action="#{knowledgeController.edit()}" value="#{messages.Edit}" rendered="#{reexaminationController.isEditable(knowledgeController.selected, null)}" immediate="true"/>
                </h:panelGrid>
                <h:inputHidden id="inputGraph" value="#{knowledgeController.getKnowledgeRelationship4dagre()}"/>

                <svg width="960" height="600"> <g/></svg>
                <script>
                    var svg = d3.select("svg"),
                            inner = d3.select("svg g"),
                            zoom = d3.zoom().on("zoom", function () {
                        inner.attr("transform", d3.event.transform);
                    });
                    svg.call(zoom);

                    // Create and configure the renderer
                    var render = dagreD3.render();

                    var g;

                    var inputGraph = document.querySelector("#inputGraph");
                    try {
                        g = graphlibDot.read(inputGraph.value);
                    } catch (e) {
                        inputGraph.setAttribute("class", "error");
                        throw e;
                    }

                    g.graph().transition = function (selection) {
                        return selection.transition().duration(500);
                    };

                    // Render the graph into svg g
                    d3.select("svg g").call(render, g);
                </script>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
